<?php
class My_Controller_Action_Helper_Jsonp
	extends Zend_Controller_Action_Helper_Json
{

    public function direct($data, $sendNow = true, $keepLayouts = false, $callback)
    {
        if ($sendNow) {
            return $this->sendJson($data, $keepLayouts, $callback);
        }
        return $this->encodeJson($data, $keepLayouts, $callback);
    }
    
    public function encodeJson($data, $keepLayouts = false, $callback)
    {
        $data = $callback . '('. parent::encodeJson($data, $keepLayouts = false).');';
        return $data;
    }
    
    
    public function sendJson($data, $keepLayouts = false, $callback)
    {
        $data = $this->encodeJson($data, $keepLayouts, $callback);
        $response = $this->getResponse();
        $response->setBody($data);

        if (!$this->suppressExit) {
            $response->sendResponse();
            exit;
        }

        return $data;
    }
    
}
